﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;

public static class AnimationClipConfig
{
    public static Bone1_Anim boneAnim = new Bone1_Anim();
    public static string path;
    public static void init( string assetPath)
    {
        boneAnim = new Bone1_Anim();
        path = assetPath.Split('.')[0] + "_anim.json";
//        if (!path.Contains("art/model/bone/"))//验证需要分割动作的fbx文件目录 其他目录下的fbx文件不进行操作
//            return;
        try
        {
            StreamReader sr = new StreamReader(path);
            string json = sr.ReadToEnd();
            sr.Close();
            if (json.Length > 0)
                boneAnim = JsonUtility.FromJson<Bone1_Anim>(json);

        }
        catch (Exception e)
        {
            Debug.Log("JsonError:"+e.Message);
        }
    }
    public static void setNeedClip()
    {
        //读取后再标记防止多次切割
        boneAnim.needclip = 1;
        string strJson = JsonUtility.ToJson(boneAnim);
        StreamWriter sw = new StreamWriter(path);
        sw.WriteLine(strJson);
        sw.Close();
    }

    public static Bone1_Expose bone_expose = new Bone1_Expose();
    public static void getJsonExpose(string assetPath)
    {
        path = assetPath.Split('.')[0] + "_expose.json";
//        if (!path.Contains("art/model/bone/"))//验证需要分割动作的fbx文件目录 其他目录下的fbx文件不进行操作
//            return;
        try
        {
            StreamReader sr = new StreamReader(path);
            string json = sr.ReadToEnd();
            sr.Close();
            if (json.Length > 0)
            {
                bone_expose = JsonUtility.FromJson<Bone1_Expose>(json);
            }

        }
        catch (Exception e)
        {
            Debug.Log("JsonError:" + e.Message);
        }
    }
    public static UIBorderRoot uiborderroot;
    public static void getJsonUIBorder(string assetPath)
    {
        path = assetPath;//assetPath.Split('.')[0] + "_border.json";
        try
        {
            StreamReader sr = new StreamReader(path);
            string json = sr.ReadToEnd();
            sr.Close();
            if (json.Length > 0)
            {
                uiborderroot = JsonUtility.FromJson<UIBorderRoot>(json);
            }

        }
        catch (Exception e)
        {
            Debug.Log("JsonError:" + e.Message);
        }
    }
}

[Serializable]
public class AudioInfo
{
    public enum AudioType
    {
        effect,
        voice,
        loop_effect,
    }
    
    public int frame;
    public string soundPath;
    public AudioType type;
}

[Serializable]
public class ClipsItem
{
    /// <summary>
    /// 动作名字
    /// </summary>
    public string clipname;
    /// <summary>
    /// 开始帧数
    /// </summary>
    public int startFrame;
    /// <summary>
    ///结束帧数
    /// </summary>
    public int endFrame;
    /// <summary>
    ///是否循环
    /// </summary>
    public bool loop;
    /// <summary>
    ///是否左右翻转
    /// </summary>
    public bool upbody;
    /// <summary>
    ///是否左右翻转
    /// </summary>
    public bool mirror;
    public float speed;
    public List<AudioInfo> audios;

}
[Serializable]
public class Bone1_Anim
{
    /// <summary>
    /// 是否需要切割处理（防止多次切割）
    /// </summary>
    public int needclip;
    /// <summary>
    /// 动作列表
    /// </summary>
    public List<ClipsItem> clips;
}
[Serializable]
public class Bone1_Expose
{
    /// <summary>
    /// 
    /// </summary>
    public string fbxname;
    /// <summary>
    /// 路径列表
    /// </summary>
    public List<ExposePath> strpath;
}
[Serializable]
public class ExposePath
{
    /// <summary>
    /// 名字
    /// </summary>
    public string exposename;

    public string exposepath;
}

[Serializable]
public class UIBorderRoot
{
    public List<UIBorderItem> strpath;
}
[Serializable]
public class UIBorderItem
{
    /// <summary>
    /// 
    /// </summary>
    public string path;
    /// <summary>
    /// 
    /// </summary>
    public int left;
    /// <summary>
    /// 
    /// </summary>
    public int top;
    /// <summary>
    /// 
    /// </summary>
    public int right;
    /// <summary>
    /// 
    /// </summary>
    public int bottom;
}